public class PalindromeList {
    public boolean chkPalindrome(ListNode A) {
        // write code here
        if( A == null) {
            return false;
        }
        if( A.next == null) {
            return true;
        }
        ListNode fast = A;
        ListNode slow = A;
        //找中间节点
        while(fast != null&&fast.next != null) {
            //快指针，一次走两步
            fast = fast.next.next;
            //慢指针，一次走一步
            slow = slow.next;
        }
        ListNode cur = slow.next;
        //局部翻转
        while( cur != null) {
            ListNode curNext = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curNext;
        }
        //判断是否回文
        while(slow != A) {
            if(slow.val != A.val) {
                return false;
            }
            if(A.next == slow) {
                return true;
            }
            slow = slow.next;
            A = A.next;
        }
        return true;
    }
}
